<template>
  <!-- 岗位设置 -->
  <div>
    <!-- 搜索 -->
    <TopFilter
      :list="topFilterInit"
      :cols="3"
      labelWidth="100"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
      ></TopFilter>
     <!-- table -->
    <FilterTable
       ref="table"
       :columns="columns"
       :fetchapi="fetchApi"
       :isSelectColumn="isSelectColumn"
       :params="flterValue"
       :datakey="'records'"
       :defaultSelections="selectionList"
       :onRowSelectChange="rows => this.selectionList = rows"
       columnsRef='origin_personnelInfo_postSet_index_01'
       :onColumnsChange="columns => this.columns = columns">
      <template slot="controls" >
       <el-button size="small" type="primary" icon="el-icon-plus" @click="dialogHandle('','add')">新增</el-button>
        <AjaxButton size="small" type="primary" icon="el-icon-download" :click="issueHandle">下发</AjaxButton>
      </template>
   </FilterTable>
    <!-- 经销商弹窗 -->
   <BaseDialog title="岗位信息维护" :visible.sync="visible"
      width="400px"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}" >
      <addDialog  v-model="initData" ref='addDialog' @close="dialogClose" />
   </BaseDialog>
  </div>
</template>
<script>
import { pageDealerStationMaintaion,issueStation } from '@/api/cms-api/personnelInfo/postSet/index';
import addDialog from './addDialog'
import { dictionary } from '@/utils/dictMixin';
export default {
  name:'personnelInfoPostSet',
  components: {
    addDialog
  },
  mixins: [dictionary],
  data() {
    return {
      visible:false,
      isSelectColumn:true,
      infoId:null,
      topFilterInit:this.topFilterInitFun(),
      flterValue:{},//IsinitParam: 1 },  //参数,默认页面为启用状态IsinitParam:1
      initData:{},
      columns:this.creatHeader(),
      fetchApi:pageDealerStationMaintaion,
      selectionList:[]

    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
      //搜索数据
      topFilterInitFun(){
        return [
            { type: 'SELECT',  label: '是否培训岗位',  fieldName: 'isTrain',  placeholder: '请选择', initialValue: "", itemList:  this.createDictList('1004') },
            { type: 'INPUT',   label: '岗位代码',    fieldName: 'stationCode',  placeholder: '请输入',  initialValue: ''},
            { type: 'INPUT',   label: '岗位名称',    fieldName: 'stationName',  placeholder: '请输入',  initialValue: ''},
            { type: 'SELECT',  label: '启用标志', fieldName: 'enable',  placeholder: '请选择', initialValue: "", itemList: this.createDictList('1003') },// this.createDictListRemoveCodes('1003', ['10031002']) }
             { type: 'SELECT',  label: '岗位类型',  fieldName: 'businessType',  placeholder: '请选择', initialValue: "", itemList:  this.createDictList('1626') },
        ]
      },
      //搜索获取数据
      changeHandle(val){
        // //编辑页面搜索条件和页面显示默认启用状态
        //   if (val.enable == 10031001 || val.enable == "") {
        //     //当enable等于启用或者""时。点击重置页面只显示默认的启用状态IsinitParam:1
        //     val = Object.assign({}, { IsinitParam: 1 },val);
        //   }//搜索全部启用禁用状态数据
            this.flterValue = Object.assign({},val);
      },
      //table表头和数据源
      creatHeader(){
         return [
         {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
         },
         {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.dialogHandle(props.row,'edit')}>编辑</el-button>
              </div>
            );
          }
        },
        { title: '岗位代码',  dataIndex: 'stationCode', sorter: true},
        { title: '岗位名称',  dataIndex: 'stationName', sorter: true},
        { title: '是否培训岗位',  dataIndex: 'isTrain', sorter: true,filterItems: this.createDictList('1004'),
           render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.isTrain, '1004')}</span>;
          }},

        { title: '岗位类型',  dataIndex: 'businessType', sorter: true,filterItems: this.createDictList('1626'),
           render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.businessType, '1626')}</span>;
          }},

        // { title: '关键提醒', dataIndex: 'keyNotification', sorter: true,filterItems: this.createDictList('1004'),
        //    render: props => {    //编码转汉字
        //     return <span>{this.createDictText(props.row.keyNotification, '1004')}</span>;
        //   }},
        { title: '岗位描述',dataIndex: 'stationDesc',  sorter: true},
        {
          title: '启用标志',
          dataIndex: 'enable',
          sorter: true,
          filterItems: this.createDictList('1003'),
         render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.enable, '1003')}</span>;
          }
        },
        { title: '最后下发时间',dataIndex: 'lastIssueTime', dateFormat: 'yyyy-MM-dd HH:mm:ss',  sorter: true},
        ]
      },
    //详情
    dialogHandle(row,tpye){
      this.visible = true;
      const pram = {
        type: tpye,
        rowData: row

      };
      this.initData=pram;

    },
    //下发
    async issueHandle(){
      let rows = this.selectionList;
      if(rows.length == 0){
        this.$message.warning("至少选择一条记录");
        return;
      }
      let ids = new Array();
      rows.forEach(row => {
        ids.push(row.stationId);
      });
      const res = await issueStation(ids.join(","));
      if(res.resultCode == 200){
        this.$notify.success("下发成功");
      }
      // 刷新列表数据
      this.flterValue = { ...this.flterValue };
    },
    //关闭详情
    dialogClose(data){
      this.visible=false
      if (data.type === 'refresh') {
        // 刷新列表数据
        this.flterValue = { ...this.flterValue };
      }
    },
     collapseHandle() {
      // this.$nextTick(() => {
      //   this.BaseTable.EXECUTE_RESET_HEIGHT();
      // });
    }
  }
};
</script>

<style lang="less" scoped>
</style>
